class UserConfigurationMismatchError(Exception): pass
"""raised when a conflicting configuration for a user is found"""


class UserAlreadyConnectedError(Exception): pass
"""raised when the user object is already connected and a configuration change is attempted"""


class UserConnectionStringInvalidError(Exception): pass
"""raised when an invalid connection string is used to create a User object"""


class AuthenticationError(Exception): pass
"""raised when there is an error authenticating (usually via SSH)"""


class UnsupportedConnectionError(Exception): pass
"""raised when the client tries to create a connection with parameters
that are not yet supported by cloudcontrol"""


class NonzeroReturnStatusError(Exception):
    """raised when a shell command returns a nonzero status code"""
    
    code = property(lambda self: self.__code)
    command = property(lambda self: self.__command)
    
    def __init__(self, code, command, message = None):
        if message and len(message.strip()) > 0:
            Exception.__init__(self, "'%s' returned exit status %s (%s)" % (command, code, message))
        else:
            Exception.__init__(self, "'%s' returned exit status %s" % (command, code))
        self.__code = code
        self.__command = command
    
    def __str__(self):
        if self.message and len(self.message) > 0:
            return "'%s' returned exit status %s (%s)" % (self.command, self.code, self.message)
        else:
            return "'%s' returned exit status %s" % (self.command, self.code)